base-compose

Selectively merge values from one or more generators onto the current application instance.
Install
Install with npm:
$ npm install base-compose --save
This plugin requires the base-generators to be registered first. If not already registered, you can do so now by following these instructions.
Usage
var compose = require('base-compose');
var Base = require('base');
var app = new Base();
app.use(compose());
API
Heads up!
Some of the methods exposed on .compose expect for app
to be an instance of templates, or for specific plugins to be registered first.
You don't need to register all of the plugins prescribed below, just use the plugins you need with the methods you need. base-compose
will give you detailed error messages when something is missing.
More information is provided in the methods documentation below.
Setup a composition by passing in an array of generators to compose elements. If a generator cannot be found, an error will be thrown.
Params
names
{String|Array}: One or more generator names.returns
{Object}: Returns an instance of Compose
Example
app.compose(['a', 'b', 'c'])
.data()
.options()
.helpers()
.views();
Merge the options from each generator into the app
options. This method requires using the [base-option][base-option] plugin.
Params
key
{String}: Optionally pass the name of a property to merge from the options
object. Dot-notation may be used for nested properties.returns
{Object}: Returns the Compose
instance for chaining
Example
a.option({foo: 'a'});
b.option({foo: 'b'});
c.option({foo: 'c'});
app.compose(['a', 'b', 'c'])
.options();
console.log(app.options);
Merge the cache.data
object from each generator onto the app.cache.data
object. This method requires the .data()
method from templates.
Params
key
{String}: Optionally pass a key to merge from the data
object.returns
{Object}: Returns the Compose
instance for chaining
Example
a.data({foo: 'a'});
b.data({foo: 'b'});
c.data({foo: 'c'});
app.compose(['a', 'b', 'c'])
.data();
console.log(app.cache.data);
Merge the engines from each generator into the app
engines. This method requires the .engine()
methods from templates.
returns
{Object}: Returns the Compose
instance for chaining
Example
app.compose(['a', 'b', 'c'])
.engines();
Merge the helpers from each generator into app.helpers
. Requires the .helper
method from templates.
returns
{Object}: Returns the Compose
instance for chaining
Example
app.compose(['a', 'b', 'c'])
.helpers();
Merge the pipeline plugins from each generator onto app.plugins
. Requires the base-pipeline plugin to be registered.
returns
{Object}: Returns the Compose
instance for chaining
Example
app.compose(['a', 'b', 'c'])
.pipeline();
Copy the specified tasks and task-dependencies from each generator onto app.tasks
. Requires using the base-task plugin to be registered.
Params
tasks
{String|Array}: One or more task names (optional)returns
{Object}: Returns the Compose
instance for chaining
Example
app.compose(['a', 'b', 'c'])
.tasks(['foo', 'bar', 'default']);
app.compose(['a', 'b', 'c'])
.tasks();
Copy view collections and views from each generator onto app
. Expects app
to be an instance of templates.
Params
names
{Array|String}: (optional) Names of one or more collections to copy. If undefined all collections will be copied.filter
{Function}: Optionally pass a filter function to filter views copied from each collection. The filter function exposes key
, view
and collection
as arguments. If used, the function must return true
to copy a view.returns
{Object}: Returns the Compose
instance for chaining
Example
app.compose(['a', 'b', 'c'])
.views();
Returns an iterator function for iterating over an array of generators. The iterator takes a fn
that exposes the current generator being iterated over (generator
) and the app passed into the original function as arguments. No binding is done within the iterator so the function passed in can be safely bound.
Params
names
{Array}: Names of generators to iterate over (optional).iteratorFn
{Function}: Function to invoke for each generator in generators
. Exposes app
and generator
as arguments.returns
{Object}: Returns the Compose
instance for chaining
Example
app.compose(['a', 'b', 'c'])
.iterator(function(generator, app) {
app.data(generator.cache.data);
});
app.compose(['a', 'b', 'c'])
.iterator(['d', 'e', 'f'], function(generator, app) {
});
base-generators
Follow these instructions to install and register the base-generators plugin before registering base-compose
.
Install base-generators
$ npm install base-generators --save
Register base-generators
var generators = require('base-generators');
var compose = require('base-compose');
var Base = require('base');
var app = new Base();
app.use(generators());
app.use(compose());
Related projects
You might also be interested in these projects:
- assemble: Assemble is a powerful, extendable and easy to use static site generator for node.js. Used… more | homepage
- base: base is the foundation for creating modular, unit testable and highly pluggable node.js applications, starting… more | homepage
- generate: Fast, composable, highly extendable project generator with a user-friendly and expressive API. | homepage
- verb: Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… more | homepage
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Building docs
Generate readme and API documentation with verb:
$ npm install verb && npm run docs
Or, if verb is installed globally:
$ verb
Running tests
Install dev dependencies:
$ npm install -d && npm test
Author
Brian Woodward
License
Copyright © 2016, Brian Woodward.
Released under the MIT license.
This file was generated by verb, v0.9.0, on April 21, 2016.